﻿using System.Windows;
using System.Windows.Controls;
using VMWorkshop.Domain;
using VMWorkshop.Wpf.Models.ViewModels;

namespace VMWorkshop.Wpf.Views
{
    /// <summary>
    /// Interaction logic for Demo.xaml
    /// </summary>
    public partial class Demo : Window
    {
        private DemoViewModel _vm;

        public Demo()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Demo_Loaded);
        }

        void Demo_Loaded(object sender, RoutedEventArgs e)
        {
            this._vm = new DemoViewModel(new ProductRepository());
            this.DataContext = this._vm;
        }

        private void productGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this._vm.GetSelectedProduct(((ProductListView)e.AddedItems[0]).ProductId);
        }

        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            this._vm.Persist();
        }
    }
}
